/**
 *
 * @author sean
 */
package post;
import java.io.*;
import java.util.Date;

public class TransactionReader {
    //private String customerName;
    //private String tenderType;
    private String inputLine;
    //private int quantity;
    private BufferedReader reader;

    public TransactionReader(String fileName) throws FileNotFoundException{
        reader = new BufferedReader( new FileReader( fileName ) );
    }//end constructor

    public boolean hasMoreTrans() throws IOException
    {
        return reader.ready();  //return true if file can still be read
    }//end hasMoreTrans

/*public String getName() throws IOException  //retrieves customers name from transaction file
{
    String cName = reader.readLine();   //gets customers name from first line of file
    return cName;
}//end getName
*/
public Item getNextItem() throws IOException
{
        double tAmt=0.;
        int qty=0;       //amount of item to be purchased
        String upc;     //upc of item to be purchased
        if( !( (inputLine=reader.readLine()).startsWith( "<" ) ) ){
            upc = inputLine.substring(0, 4);    //first four characters of line is upc
            qty = Integer.parseInt(inputLine.substring(9)); //get the amount of items to be purchased
            return new Item( upc, qty );
        } //loop to get all items in list
    return null;
}

public Payment getPayment() throws IOException
{
    int cardNum;
    double tAmt;
        if( inputLine.charAt(2) == 'A') //Checks from cash payment
        {
            tAmt = Double.parseDouble(inputLine.substring(9, inputLine.length() - 1));  //find amount of cash
            return new CashPayment( tAmt );
        } 
        else if ( inputLine.charAt(2) == 'H' )  //Checks for Check payment
        {
            tAmt = Double.parseDouble(inputLine.substring(10, inputLine.length() - 1)); //find amount on check
            return new CheckPayment( tAmt );
        }
        else    //else Credit payment
        {
            cardNum = Integer.parseInt(inputLine.substring(10, 15));    //find card number
            return new CreditPayment( cardNum );
        }
}


}//end transaction class